<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
    <title>Virus Bacteria Interaction Prediction</title>
    <link rel="stylesheet" type="text/css" href="lib/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/jquery-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="lib/jqwidgets/styles/jqx.base.css" />
    <link rel="stylesheet" type="text/css" href="css/styles.css"/>
    <link rel="stylesheet" type="text/css" href="lib/css/custom_new.css">
    
    <script type="text/javascript" src="lib/js/d3.js"></script>
    <script type="text/javascript" src="lib/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="lib/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="lib/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="lib/js/math.min.js"></script>
    <script type="text/javascript" src="lib/jqwidgets/jqx-all.js"></script>
</head>


<body>
	
<div id="tooltip1" class="hidden"><p><span id="value"></div>

<div id="container-id-1" style="width: 1670px; height: 1000px; clear: both;">
	<div class="sidebar_wrapper" style="float: left; width: 300px; height: 1000px; overflow: hidden; display: block; border-right: 1px solid grey;">
		<div class="title_section">
			<img class="title_image" src="logo.jpg" alt="" style="width: 290px; margin-left: 2px; margin-top: 5px;">
		</div>
		
		<div class="reorder_section" style="margin: 1px; margin-top: 10px; padding:2px; font-size: 11px; border: 0.5px solid grey;">
			<div id='jqxWidget'><label>Select the Virus for visualization: </label><div id="listbox"></div></div>
			
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="topAmount"># of top Hosts: </label><input type="text" value="25" id="topAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="topSlider" style="width: 290px;"></div>
			</div>
			<div class="opacity_slider_container" style="margin-top: 5px;">
				<div ><label for="cutoffAmount">Max distance &lt;= </label><input type="text" value="1" id="cutoffAmount" readonly style="border:0; font-weight:bold; width: 50px;"></div>
				<div id="cutoffSlider" style="width: 290px;"></div>
			</div>
			<div class="btn-group gene_search_button" data-toggle="buttons" style="margin-top: 10px;">
				<div><button id="okBtn" class="sidebar_text btn btn-primary submit_gene_button" type="button" disabled="true" onclick="updateData()" style="float: left; padding-top: 6px; padding-bottom: 6px;">OK</button></div>
			</div>
		</div>
	</div>
	<div id="vizcontainer" style="float: left; width: 1000px; height: 800px; overflow: auto; ">
		<svg id="heatCanvas"></svg> 
	</div>
	<div style="float: left;margin-left: 20px; margin-top: 50px; ">
		<div><b>Consensus Information</b></div>
		<div id="consensusSuperkingdom"></div>
		<div id="consensusPhylum"></div>
		<div id="consensusClass"></div>
		<div id="consensusOrder"></div>
		<div id="consensusFamily"></div>
		<div id="consensusGenus"></div>
		<div id="consensusSpecies"></div>
	</div>
</div>


<footer id="footer_div" class="footer navbar-fixed-bottom">
    <div class="row"><div class="col-xs-12 footer_section"><p class="text-muted">Copyright (C) 2016 Yang Lu &lt;<a href="mailto:ylu465@usc.edu">ylu465@usc.edu</a>&gt; @ Computational and Molecular Biology, Department of Biological Science, University of Southern California, LA, CA 90089, USA </p></div></div>
</footer>

<script type="text/javascript">
	var margin = {top: 200, right: 10, bottom: 10, left: 200};
   var colors = ['#91003F','#9B1A53','#A63467','#B14F7C','#BB6990','#C684A4','#D19EB9','#DBB9CD','#E6D3E1','#F1EEF6','#FFFFFF'];
   
   var virusNameIdxMap = new Object(), hostNameIdxMap = new Object();   
   var topHostNum = 50, cutoff = 1;
   var checkedVirusIdxArr = [], checkedVirusArr = [], hostArr = [], edgeData =[];
   var virusNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var hostNameArr = ["NC_019843.3.fasta", "NC_004297.0.fasta", "NC_001802.1.fasta", "NC_001722.1.fasta", "NC_002023.0.fasta", "NC_004718.3.fasta", "NC_006998.1.fasta", "AC_000017.1.fasta", "NC_003977.2.fasta", "NC_012532.1.fasta", "NC_045512.2.fasta", "NC_038312.1.fasta", "NC_002728.1.fasta", "NC_006273.2.fasta", "NC_001803.1.fasta", "NC_009333.1.fasta", "NC_001348.1.fasta", "NC_001798.2.fasta", "NC_001538.1.fasta", "NC_001355.1.fasta", "NC_001436.1.fasta", "NC_005219.1.fasta", "NC_001430.1.fasta", "NC_001906.3.fasta", "NC_038311.1.fasta", "NC_010415.1.fasta", "NC_001731.1.fasta", "JX276378.1.fasta", "NC_006307.0.fasta", "NC_001806.2.fasta", "NC_001796.2.fasta", "NC_001611.1.fasta", "NC_003443.1.fasta", "NC_001664.4.fasta", "NC_002549.1.fasta", "NC_004102.1.fasta", "NC_002204.0.fasta", "NC_007605.1.fasta", "NC_004162.2.fasta"];
var virusHostMat = [[2.22045e-16,0.0712006,0.0879792,0.100403,0.0897208,0.0248716,0.107644,0.140769,0.152479,0.129374,0.0296249,0.0756152,0.0723787,0.189305,0.0741158,0.115234,0.0869479,0.353806,0.114218,0.0982018,0.168313,0.0989352,0.0723942,0.0724132,0.0794795,0.0826734,0.28789,0.0961758,0.0940232,0.32822,0.0889077,0.103708,0.0652944,0.0806877,0.0588098,0.201582,0.076856,0.205289,0.0986922],
[0.0712006,-3.33067e-16,0.107538,0.116187,0.0746283,0.0694068,0.143874,0.172024,0.162234,0.116771,0.0777123,0.0996486,0.0672835,0.226338,0.101144,0.142094,0.134667,0.371382,0.134061,0.15381,0.173305,0.115563,0.0922144,0.0662266,0.103958,0.100038,0.321401,0.111814,0.0922014,0.346971,0.0869084,0.142893,0.0720689,0.111068,0.0645757,0.210565,0.0777056,0.206193,0.132206],
[0.0879792,0.107538,-3.33067e-16,0.0684994,0.101636,0.0862819,0.132911,0.165668,0.164677,0.130819,0.0926085,0.105019,0.0993478,0.223623,0.11673,0.130062,0.133073,0.352829,0.106259,0.131899,0.14939,0.124088,0.0983248,0.097121,0.112011,0.124522,0.316885,0.140156,0.0935196,0.329403,0.111086,0.131944,0.096327,0.106992,0.0921689,0.199346,0.0766169,0.19012,0.127782],
[0.100403,0.116187,0.0684994,4.44089e-16,0.102406,0.102505,0.166628,0.140549,0.140506,0.11067,0.117338,0.120008,0.120566,0.195479,0.150203,0.107439,0.136146,0.32188,0.122319,0.147585,0.125,0.143133,0.108449,0.11525,0.130016,0.123409,0.282342,0.128854,0.112342,0.297558,0.141384,0.167274,0.11338,0.123972,0.107615,0.169239,0.0881931,0.156877,0.107589],
[0.0897208,0.0746283,0.101636,0.102406,-3.33067e-16,0.083147,0.154309,0.157302,0.152138,0.0964987,0.105995,0.107242,0.0815706,0.201295,0.128244,0.12237,0.122987,0.34711,0.13593,0.157327,0.156138,0.124169,0.0927358,0.0805132,0.120596,0.102547,0.29917,0.10695,0.0774394,0.322142,0.106267,0.156493,0.0812443,0.100687,0.0715896,0.189193,0.063948,0.190554,0.116487],
[0.0248716,0.0694068,0.0862819,0.102505,0.083147,5.55112e-17,0.12097,0.149601,0.157563,0.125615,0.0224281,0.0725122,0.0705652,0.197626,0.0793018,0.125433,0.102418,0.365407,0.116993,0.10702,0.179369,0.0984377,0.0694953,0.0725558,0.0768202,0.0782958,0.292186,0.0939654,0.0853347,0.341389,0.0912219,0.117211,0.0686929,0.0847165,0.0558043,0.205528,0.0681856,0.213781,0.103446],
[0.107644,0.143874,0.132911,0.166628,0.154309,0.12097,1.66533e-16,0.234863,0.227077,0.241564,0.101881,0.120263,0.0789933,0.25694,0.054347,0.201691,0.0944723,0.403879,0.139959,0.131731,0.24672,0.145168,0.153271,0.0905192,0.0975902,0.186231,0.370107,0.197562,0.117398,0.386087,0.0614126,0.00326015,0.0826413,0.0687658,0.095453,0.295911,0.120172,0.301732,0.190717],
[0.140769,0.172024,0.165668,0.140549,0.157302,0.149601,0.234863,-3.33067e-16,0.162698,0.120054,0.174635,0.183012,0.190855,0.0492608,0.224077,0.0354179,0.102694,0.131154,0.18402,0.182847,0.100852,0.205996,0.158211,0.18343,0.200503,0.150836,0.112016,0.134078,0.196268,0.116113,0.226398,0.238367,0.186417,0.12957,0.151273,0.0807199,0.167789,0.0744614,0.0895128],
[0.152479,0.162234,0.164677,0.140506,0.152138,0.157563,0.227077,0.162698,1.66533e-16,0.145336,0.173005,0.175701,0.17014,0.199311,0.207258,0.132832,0.158717,0.309308,0.187981,0.194616,0.156254,0.189628,0.153855,0.164612,0.195287,0.159679,0.28436,0.15828,0.177527,0.283717,0.198576,0.228725,0.175131,0.165927,0.155085,0.186203,0.154809,0.177128,0.151093],
[0.129374,0.116771,0.130819,0.11067,0.0964987,0.125615,0.241564,0.120054,0.145336,-2.22045e-16,0.15961,0.153491,0.152917,0.16104,0.209536,0.087196,0.155439,0.288051,0.176905,0.198784,0.119121,0.169663,0.126701,0.139877,0.175397,0.119137,0.24847,0.1136,0.157844,0.258747,0.192402,0.245883,0.150516,0.157605,0.130617,0.127114,0.122734,0.123396,0.103542],
[0.0296249,0.0777123,0.0926085,0.117338,0.105995,0.0224281,0.101881,0.174635,0.173005,0.15961,-5.55112e-16,0.0732679,0.0744687,0.223366,0.0637295,0.150308,0.100302,0.385517,0.112657,0.0999113,0.202248,0.100208,0.0796422,0.0800474,0.071288,0.0972018,0.325041,0.113584,0.0857248,0.362631,0.0837936,0.0967558,0.0732871,0.0809543,0.0612282,0.237945,0.0777302,0.242958,0.126197],
[0.0756152,0.0996486,0.105019,0.120008,0.107242,0.0725122,0.120263,0.183012,0.175701,0.153491,0.0732679,1.66533e-16,0.0916381,0.23446,0.0897654,0.145307,0.11555,0.373091,0.13721,0.120816,0.184039,0.1076,0.0791749,0.0906726,0.0866117,0.096783,0.335225,0.112283,0.109113,0.346677,0.0961604,0.116286,0.0876805,0.103847,0.0842491,0.233629,0.0918616,0.22553,0.143818],
[0.0723787,0.0672835,0.0993478,0.120566,0.0815706,0.0705652,0.0789933,0.190855,0.17014,0.152917,0.0744687,0.0916381,-2.22045e-16,0.233747,0.0607794,0.159033,0.113952,0.381809,0.124904,0.14395,0.188897,0.108879,0.0969524,0.0310342,0.0823063,0.116092,0.339489,0.128359,0.073939,0.360095,0.0430913,0.0769165,0.0404053,0.0832299,0.0488856,0.235636,0.072314,0.236659,0.143049],
[0.189305,0.226338,0.223623,0.195479,0.201295,0.197626,0.25694,0.0492608,0.199311,0.16104,0.223366,0.23446,0.233747,0,0.27533,0.056679,0.116935,0.112156,0.25237,0.228856,0.157901,0.258391,0.21598,0.225505,0.250158,0.196636,0.0885616,0.173404,0.25019,0.101779,0.268588,0.264009,0.236259,0.142799,0.195134,0.102426,0.222653,0.112267,0.104047],
[0.0741158,0.101144,0.11673,0.150203,0.128244,0.0793018,0.054347,0.224077,0.207258,0.209536,0.0637295,0.0897654,0.0607794,0.27533,1.66533e-16,0.197659,0.110535,0.415188,0.126006,0.115518,0.231981,0.115715,0.114421,0.0716192,0.0726713,0.138897,0.378295,0.157246,0.0985452,0.394801,0.0470941,0.048525,0.0609802,0.0885415,0.0704424,0.28348,0.0961295,0.288817,0.182302],
[0.115234,0.142094,0.130062,0.107439,0.12237,0.125433,0.201691,0.0354179,0.132832,0.087196,0.150308,0.145307,0.159033,0.056679,0.197659,4.996e-16,0.0708333,0.154413,0.164467,0.148618,0.0790585,0.172234,0.127291,0.149352,0.168876,0.116744,0.155337,0.0993706,0.174961,0.126251,0.195248,0.205325,0.158333,0.0992235,0.122628,0.0679027,0.139134,0.0523134,0.0627805],
[0.0869479,0.134667,0.133073,0.136146,0.122987,0.102418,0.0944723,0.102694,0.158717,0.155439,0.100302,0.11555,0.113952,0.116935,0.110535,0.0708333,-4.44089e-16,0.24121,0.14374,0.0992257,0.143842,0.143844,0.124158,0.115634,0.118871,0.125053,0.241269,0.122565,0.135085,0.212399,0.1236,0.0956631,0.112704,0.0415544,0.0876175,0.155983,0.116317,0.158655,0.0999154],
[0.353806,0.371382,0.352829,0.32188,0.34711,0.365407,0.403879,0.131154,0.309308,0.288051,0.385517,0.373091,0.381809,0.112156,0.415188,0.154413,0.24121,0,0.380188,0.357846,0.212747,0.388517,0.356366,0.373528,0.390045,0.335754,0.137636,0.31091,0.39547,0.00807949,0.408637,0.408725,0.382152,0.301991,0.349109,0.162018,0.369137,0.119069,0.257773],
[0.114218,0.134061,0.106259,0.122319,0.13593,0.116993,0.139959,0.18402,0.187981,0.176905,0.112657,0.13721,0.124904,0.25237,0.126006,0.164467,0.14374,0.380188,4.44089e-16,0.13708,0.17633,0.13972,0.134497,0.133619,0.132639,0.161069,0.346251,0.166918,0.109355,0.35803,0.1408,0.140273,0.125304,0.116735,0.115167,0.231059,0.106148,0.230668,0.162888],
[0.0982018,0.15381,0.131899,0.147585,0.157327,0.10702,0.131731,0.182847,0.194616,0.198784,0.0999113,0.120816,0.14395,0.228856,0.115518,0.148618,0.0992257,0.357846,0.13708,-1.11022e-16,0.197529,0.134546,0.134683,0.148706,0.113198,0.146034,0.324735,0.151319,0.156879,0.333132,0.140353,0.125174,0.132096,0.114164,0.126089,0.233241,0.138781,0.231555,0.156276],
[0.168313,0.173305,0.14939,0.125,0.156138,0.179369,0.24672,0.100852,0.156254,0.119121,0.202248,0.184039,0.188897,0.157901,0.231981,0.0790585,0.143842,0.212747,0.17633,0.197529,0,0.208178,0.164053,0.182301,0.207756,0.162972,0.249807,0.152833,0.197279,0.184003,0.229269,0.248492,0.190151,0.167508,0.163539,0.114854,0.164107,0.0774387,0.134995],
[0.0989352,0.115563,0.124088,0.143133,0.124169,0.0984377,0.145168,0.205996,0.189628,0.169663,0.100208,0.1076,0.108879,0.258391,0.115715,0.172234,0.143844,0.388517,0.13972,0.134546,0.208178,-2.22045e-16,0.116032,0.107667,0.112603,0.134693,0.352368,0.139026,0.128671,0.363381,0.121052,0.143237,0.109265,0.130428,0.104163,0.2447,0.116544,0.248611,0.156839],
[0.0723942,0.0922144,0.0983248,0.108449,0.0927358,0.0694953,0.153271,0.158211,0.153855,0.126701,0.0796422,0.0791749,0.0969524,0.21598,0.114421,0.127291,0.124158,0.356366,0.134497,0.134683,0.164053,0.116032,-4.44089e-16,0.092591,0.0931607,0.0813955,0.315057,0.0922856,0.106977,0.328123,0.112035,0.150654,0.0901825,0.120608,0.0862482,0.206279,0.0885677,0.196761,0.122963],
[0.0724132,0.0662266,0.097121,0.11525,0.0805132,0.0725558,0.0905192,0.18343,0.164612,0.139877,0.0800474,0.0906726,0.0310342,0.225505,0.0716192,0.149352,0.115634,0.373528,0.133619,0.148706,0.182301,0.107667,0.092591,1.66533e-16,0.0850486,0.109863,0.33091,0.123454,0.0850748,0.350888,0.0487213,0.0894193,0.0447058,0.0903293,0.0495527,0.222117,0.0766509,0.225238,0.134267],
[0.0794795,0.103958,0.112011,0.130016,0.120596,0.0768202,0.0975902,0.200503,0.195287,0.175397,0.071288,0.0866117,0.0823063,0.250158,0.0726713,0.168876,0.118871,0.390045,0.132639,0.113198,0.207756,0.112603,0.0931607,0.0850486,-1.11022e-16,0.113462,0.350006,0.124388,0.0995972,0.366688,0.0825133,0.0917568,0.0805797,0.106132,0.0822755,0.254364,0.0989883,0.249503,0.158193],
[0.0826734,0.100038,0.124522,0.123409,0.102547,0.0782958,0.186231,0.150836,0.159679,0.119137,0.0972018,0.096783,0.116092,0.196636,0.138897,0.116744,0.125053,0.335754,0.161069,0.146034,0.162972,0.134693,0.0813955,0.109863,0.113462,5.55112e-17,0.289586,0.084695,0.132093,0.307932,0.14416,0.183805,0.113341,0.132816,0.0972008,0.184209,0.105441,0.184321,0.117477],
[0.28789,0.321401,0.316885,0.282342,0.29917,0.292186,0.370107,0.112016,0.28436,0.24847,0.325041,0.335225,0.339489,0.0885616,0.378295,0.155337,0.241269,0.137636,0.346251,0.324735,0.249807,0.352368,0.315057,0.33091,0.350006,0.289586,4.996e-16,0.272596,0.344582,0.146415,0.369273,0.375611,0.335786,0.262634,0.301685,0.176256,0.323853,0.196475,0.20411],
[0.0961758,0.111814,0.140156,0.128854,0.10695,0.0939654,0.197562,0.134078,0.15828,0.1136,0.113584,0.112283,0.128359,0.173404,0.157246,0.0993706,0.122565,0.31091,0.166918,0.151319,0.152833,0.139026,0.0922856,0.123454,0.124388,0.084695,0.272596,1.66533e-16,0.151229,0.280145,0.162225,0.195954,0.129464,0.136583,0.106455,0.167724,0.119954,0.161967,0.110439],
[0.0940232,0.0922014,0.0935196,0.112342,0.0774394,0.0853347,0.117398,0.196268,0.177527,0.157844,0.0857248,0.109113,0.073939,0.25019,0.0985452,0.174961,0.135085,0.39547,0.109355,0.156879,0.197279,0.128671,0.106977,0.0850748,0.0995972,0.132093,0.344582,0.151229,5.55112e-17,0.376661,0.0823856,0.117914,0.0834692,0.0892909,0.0704689,0.253215,0.0547279,0.252032,0.158458],
[0.32822,0.346971,0.329403,0.297558,0.322142,0.341389,0.386087,0.116113,0.283717,0.258747,0.362631,0.346677,0.360095,0.101779,0.394801,0.126251,0.212399,0.00807949,0.35803,0.333132,0.184003,0.363381,0.328123,0.350888,0.366688,0.307932,0.146415,0.280145,0.376661,5.55112e-17,0.389645,0.390842,0.360662,0.279371,0.324839,0.136062,0.345098,0.0906536,0.230559],
[0.0889077,0.0869084,0.111086,0.141384,0.106267,0.0912219,0.0614126,0.226398,0.198576,0.192402,0.0837936,0.0961604,0.0430913,0.268588,0.0470941,0.195248,0.1236,0.408637,0.1408,0.140353,0.229269,0.121052,0.112035,0.0487213,0.0825133,0.14416,0.369273,0.162225,0.0823856,0.389645,4.996e-16,0.0574253,0.0474439,0.0931488,0.065052,0.280565,0.0849867,0.27988,0.178745],
[0.103708,0.142893,0.131944,0.167274,0.156493,0.117211,0.00326015,0.238367,0.228725,0.245883,0.0967558,0.116286,0.0769165,0.264009,0.048525,0.205325,0.0956631,0.408725,0.140273,0.125174,0.248492,0.143237,0.150654,0.0894193,0.0917568,0.183805,0.375611,0.195954,0.117914,0.390842,0.0574253,6.66134e-16,0.0788793,0.0735934,0.0947076,0.302108,0.11973,0.305198,0.194187],
[0.0652944,0.0720689,0.096327,0.11338,0.0812443,0.0686929,0.0826413,0.186417,0.175131,0.150516,0.0732871,0.0876805,0.0404053,0.236259,0.0609802,0.158333,0.112704,0.382152,0.125304,0.132096,0.190151,0.109265,0.0901825,0.0447058,0.0805797,0.113341,0.335786,0.129464,0.0834692,0.360662,0.0474439,0.0788793,-4.44089e-16,0.0923138,0.0528102,0.234006,0.0773036,0.237209,0.144557],
[0.0806877,0.111068,0.106992,0.123972,0.100687,0.0847165,0.0687658,0.12957,0.165927,0.157605,0.0809543,0.103847,0.0832299,0.142799,0.0885415,0.0992235,0.0415544,0.301991,0.116735,0.114164,0.167508,0.130428,0.120608,0.0903293,0.106132,0.132816,0.262634,0.136583,0.0892909,0.279371,0.0931488,0.0735934,0.0923138,-3.33067e-16,0.0654732,0.184833,0.0890101,0.202064,0.106492],
[0.0588098,0.0645757,0.0921689,0.107615,0.0715896,0.0558043,0.095453,0.151273,0.155085,0.130617,0.0612282,0.0842491,0.0488856,0.195134,0.0704424,0.122628,0.0876175,0.349109,0.115167,0.126089,0.163539,0.104163,0.0862482,0.0495527,0.0822755,0.0972008,0.301685,0.106455,0.0704689,0.324839,0.065052,0.0947076,0.0528102,0.0654732,5.55112e-17,0.198724,0.0647281,0.204393,0.116956],
[0.201582,0.210565,0.199346,0.169239,0.189193,0.205528,0.295911,0.0807199,0.186203,0.127114,0.237945,0.233629,0.235636,0.102426,0.28348,0.0679027,0.155983,0.162018,0.231059,0.233241,0.114854,0.2447,0.206279,0.222117,0.254364,0.184209,0.176256,0.167724,0.253215,0.136062,0.280565,0.302108,0.234006,0.184833,0.198724,-2.22045e-16,0.216027,0.075413,0.121558],
[0.076856,0.0777056,0.0766169,0.0881931,0.063948,0.0681856,0.120172,0.167789,0.154809,0.122734,0.0777302,0.0918616,0.072314,0.222653,0.0961295,0.139134,0.116317,0.369137,0.106148,0.138781,0.164107,0.116544,0.0885677,0.0766509,0.0989883,0.105441,0.323853,0.119954,0.0547279,0.345098,0.0849867,0.11973,0.0773036,0.0890101,0.0647281,0.216027,-3.33067e-16,0.213051,0.128824],
[0.205289,0.206193,0.19012,0.156877,0.190554,0.213781,0.301732,0.0744614,0.177128,0.123396,0.242958,0.22553,0.236659,0.112267,0.288817,0.0523134,0.158655,0.119069,0.230668,0.231555,0.0774387,0.248611,0.196761,0.225238,0.249503,0.184321,0.196475,0.161967,0.252032,0.0906536,0.27988,0.305198,0.237209,0.202064,0.204393,0.075413,0.213051,0,0.133188],
[0.0986922,0.132206,0.127782,0.107589,0.116487,0.103446,0.190717,0.0895128,0.151093,0.103542,0.126197,0.143818,0.143049,0.104047,0.182302,0.0627805,0.0999154,0.257773,0.162888,0.156276,0.134995,0.156839,0.122963,0.134267,0.158193,0.117477,0.20411,0.110439,0.158458,0.230559,0.178745,0.194187,0.144557,0.106492,0.116956,0.121558,0.128824,0.133188,3.33067e-16]];
var superkingdomArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var phylumArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var classArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var orderArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var familyArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var genusArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var speciesArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];
var organismArr = ["unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown"];

   for(var hostIdx=0; hostIdx<hostNameArr.length; hostIdx++) hostNameIdxMap[hostNameArr[hostIdx]] = hostIdx;
   for(var virusIdx=0; virusIdx<virusNameArr.length; virusIdx++) virusNameIdxMap[virusNameArr[virusIdx]] = virusIdx;
   console.log("phageToHost finish loading!");
   
   topHostNum = Math.min(25, hostNameArr.length);
   
   $(function() { $( "#topSlider" ).slider({ value:25, min: 1, max: 100, step: 1, slide: function( event, ui ) { $( "#topAmount" ).val( ui.value ); topHostNum = Math.min(ui.value, hostNameArr.length);  } }); }); 
   $(function() { $( "#cutoffSlider" ).slider({ value:1, min: 0, max: 1, step: 0.01, slide: function( event, ui ) { $( "#cutoffAmount" ).val( ui.value ); cutoff = ui.value; } }); });
   
   
   $("#listbox").jqxListBox({width: 290, height: 300, source: virusNameArr, checkboxes: true, filterable: true});
		$("#listbox").on('checkChange', function (event) {
			var items = $("#listbox").jqxListBox('getCheckedItems');
			checkedVirusIdxArr = []; checkedVirusArr = [];
			$.each(items, function (index) { checkedVirusIdxArr.push(this.index); checkedVirusArr.push(this.label); });
			
			if(checkedVirusIdxArr.length > 0) $("#okBtn").prop('disabled', false);
			else $("#okBtn").prop('disabled', true);
   });
   
   var host2organism = [], host2superkingdom = [], host2phylum = [], host2class = [], 
		host2order = [], host2family = [], host2genus = [], host2species = [];
   
   for(var t=0; t<hostNameArr.length; t++){
   		host2organism[hostNameArr[t]] = organismArr[t];
   		host2superkingdom[hostNameArr[t]] = superkingdomArr[t];
   		host2phylum[hostNameArr[t]] = phylumArr[t];
   		host2class[hostNameArr[t]] = classArr[t];
   		host2order[hostNameArr[t]] = orderArr[t];
   		host2family[hostNameArr[t]] = familyArr[t];
   		host2genus[hostNameArr[t]] = genusArr[t];
   		host2species[hostNameArr[t]] = speciesArr[t];
	}
	console.log("hostTaxonomy finish loading!");
	
	var minDist = 1, maxDist = 0, gap=0;
	for(var rowIdx=0; rowIdx<virusHostMat.length; rowIdx++) 
	{
		for(var colIdx=0; colIdx<virusHostMat[0].length; colIdx++)
		{
			if(virusHostMat[rowIdx][colIdx]<minDist) minDist = virusHostMat[rowIdx][colIdx];
			if(virusHostMat[rowIdx][colIdx]>maxDist) maxDist = virusHostMat[rowIdx][colIdx];
		}
	}
	minDist = Math.max(0,minDist-0.1); maxDist = Math.min(1,maxDist+0.1); gap = maxDist-minDist;
	var colorScale = d3.scale.quantile().domain([minDist,maxDist]).range(colors);

	function updateData() {
		topHostNum = Math.min(topHostNum, hostNameArr.length);

		var combinedArr = new Array(virusHostMat[checkedVirusIdxArr[0]].length).fill(0);
		for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) {
			for(var colIdx=0; colIdx<virusHostMat[checkedVirusIdxArr[rowIdx]].length; colIdx++) {
				combinedArr[colIdx] += virusHostMat[checkedVirusIdxArr[rowIdx]][colIdx];
			}
		}
		var tmpArr = combinedArr.slice(); 
		var thres = tmpArr.sort().slice(topHostNum-1,topHostNum);

		indiceArr = [];
		for(var colIdx=0; colIdx<combinedArr.length; colIdx++) {
			if(indiceArr.length >= topHostNum) break;
			if(combinedArr[colIdx] <= thres) { indiceArr.push({"idx":colIdx, "dist":combinedArr[colIdx] }); }
		}
		
		hostArr = []; edgeData =[];
		for(var colIdx=0; colIdx<indiceArr.length; colIdx++) {
			var realColIdx = indiceArr[colIdx].idx;
			hostArr.push(hostNameArr[realColIdx]);
			
			for(var rowIdx=0; rowIdx<checkedVirusIdxArr.length; rowIdx++) { edgeData.push({"row":rowIdx, "col":hostArr.length-1, 
				"value":virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]<=cutoff?virusHostMat[checkedVirusIdxArr[rowIdx]][realColIdx]:1}); }
		}
		
		pathArr = [];
		for(var colIdx=0; colIdx<hostArr.length; colIdx++) { pathArr.push([host2superkingdom[hostArr[colIdx]],host2phylum[hostArr[colIdx]],host2class[hostArr[colIdx]],host2order[hostArr[colIdx]],host2family[hostArr[colIdx]],host2genus[hostArr[colIdx]],host2species[hostArr[colIdx]]]); }
		//rootNode = 	convertToHierarchy(pathArr);
		//consensusArr = getConsensusTaxonomy(rootNode); 
		
		$("#consensusSuperkingdom").text("Superkingdom: "+getConsensusItem(pathArr,0));
		$("#consensusPhylum").text("Phylum: "+getConsensusItem(pathArr,1));
		$("#consensusClass").text("Class: "+getConsensusItem(pathArr,2));
		$("#consensusOrder").text("Order: "+getConsensusItem(pathArr,3));
		$("#consensusFamily").text("Family: "+getConsensusItem(pathArr,4));
		$("#consensusGenus").text("Genus: "+getConsensusItem(pathArr,5));
		$("#consensusSpecies").text("Species: "+getConsensusItem(pathArr,6));
		
		var cellSize = 25, legendElementWidth = cellSize*2, 
			width = Math.max(hostArr.length*cellSize, 1000 ), height = Math.max(checkedVirusIdxArr.length*cellSize, 700 );
		
		console.log();
		
		d3.selectAll(".canvasSvg").remove(); 
		var svg = d3.select("#heatCanvas").style("float", "left").attr("width", width).attr("height", height)
			.append("g").attr('class', "canvasSvg").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
			
		var rowLabels = svg.append("g").selectAll(".rowLabelg").data(checkedVirusArr).enter().append("text")
			.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "end").attr("transform", "translate(-6," + cellSize / 1.5 + ")")
      		.attr("class", function (d,i) { return "rowLabel mono r"+i;} ) ;
      		
      	var colLabels = svg.append("g").selectAll(".colLabelg").data(hostArr).enter().append("text")
      		.text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * cellSize; })
      		.style("text-anchor", "left").attr("transform", "translate("+cellSize/2 + ",-6) rotate (-90)")
      		.attr("class",  function (d,i) { return "colLabel mono c"+i;} );
      	
      	var heatMap = svg.append("g").attr("class","g3").selectAll(".cellg").data(edgeData).enter().append("rect")
			.attr("x", function(d) { return d.col * cellSize; }).attr("y", function(d) { return d.row * cellSize; })
        	.attr("class", function(d){return "cell cell-border cr"+(d.row)+" cc"+(d.col);})
        	.attr("width", cellSize).attr("height", cellSize).style("fill", function(d) { return colorScale(d.value); })
			.on("mouseover", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",true);
				d3.selectAll(".rowLabel").classed("text-highlight",function(r,ri){ return ri==d.row;});
				d3.selectAll(".colLabel").classed("text-highlight",function(c,ci){ return ci==d.col;});
				
				d3.select("#tooltip1").style("left", (d3.event.pageX+10) + "px").style("top", (d3.event.pageY-10) + "px")
					.html("Host Information: "+
						"<br> Superkingdom: "+ host2superkingdom[hostArr[d.col]] +
						"<br> Phylum: "+ host2phylum[hostArr[d.col]] +
						"<br> Class: "+ host2class[hostArr[d.col]] +
						"<br> Order: "+ host2order[hostArr[d.col]] +
						"<br> Family: "+ host2family[hostArr[d.col]] +
						"<br> Genus: "+ host2genus[hostArr[d.col]] +
						"<br> Species: "+ host2species[hostArr[d.col]] +
						"<br> Organism: "+ host2organism[hostArr[d.col]] +
						"<br> distance:"+d.value);  
                d3.select("#tooltip1").classed("hidden", false);
			})
			.on("mouseout", function(d){
				d3.selectAll(".cell").filter(function(el) {return d.row == el.row || d.col == el.col; }).classed("cell-hover",false);
				d3.selectAll(".rowLabel").classed("text-highlight",false);
				d3.selectAll(".colLabel").classed("text-highlight",false);
				d3.select("#tooltip1").classed("hidden", true);
			});
      		
      	var legend = svg.selectAll(".legend").data([minDist,minDist+0.1*gap,minDist+0.2*gap,minDist+0.3*gap,minDist+0.4*gap,minDist+0.5*gap,minDist+0.6*gap,minDist+0.7*gap,minDist+0.8*gap,minDist+0.9*gap,maxDist]).enter().append("g").attr("class", "legend");
		legend.append("rect").attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*2) - margin.top)
    		.attr("width", legendElementWidth).attr("height", cellSize)
    		.style("fill", function(d, i) { return colors[i]; });
    
    	legend.append("text").text(function(d) { return d3.format(".2f")(d); }).style("text-anchor", "left")
    		.attr("x", function(d, i) { return legendElementWidth * i-margin.left; }).attr("y", (cellSize*4)- margin.top);
	}
	
	function getConsensusItem(pathArr, idx)
	{
		var node = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) 
		{
			var path = pathArr[i];
			node.cnt ++;
			item = path[idx];
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			node.children[item].cnt ++;
		}
		
		var arr = Object.keys( node.children ).map(function ( key ) { return node.children[key].cnt; });
		var ratio = 100;
		if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
		maxItem = Object.keys(node.children)[arr.indexOf(Math.max.apply(Math,arr))];
		return node.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)";
	}
	
	function convertToHierarchy(pathArr) {
		var rootNode = {id:"root", cnt:0, children:{}};
		for (var i = 0; i < pathArr.length; i++) {
			var path = pathArr[i];
			buildNodeRecursive(rootNode, path, 0);
		}
		return rootNode;
	}
	
	function buildNodeRecursive(node, path, idx) {
		if (idx < path.length) {
			node.cnt ++;
			item = path[idx];			
			if (!node.children[item]) node.children[item] = {id:item, cnt:0, children:{}};
			buildNodeRecursive(node.children[item], path, idx + 1);
		}
	}
	
	function getConsensusTaxonomy(currNode) {
		if(currNode.children && Object.keys(currNode.children).length > 0) {
			var arr = Object.keys( currNode.children ).map(function ( key ) { return currNode.children[key].cnt; });
			//console.log(arr + " : " +arr.length);
			//console.log(arr + " : " +Math.max.apply(Math,arr) +" : " + arr.indexOf(Math.max.apply(Math,arr)));
			//console.log(Math.max.apply(Math,arr) + " / " +math.sum(arr));
			
			var ratio = 100;
			if(math.sum(arr) > 0) ratio = Math.max.apply(Math,arr)*100/math.sum(arr);
			
			maxItem = Object.keys(currNode.children)[arr.indexOf(Math.max.apply(Math,arr))];
			
			returnArr = [currNode.children[maxItem].id+" ("+String(Math.round(ratio * 100) / 100)+"%)"];
			returnArr = returnArr.concat(getConsensusTaxonomy(currNode.children[maxItem]));
			return returnArr;
		}
		return [currNode.id+" (100%)"];
	}
	

</script>

</body>
</html>